#include<iostream>

using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, k, count1 = 0, count0 = 0;
        cin >> n >> k;
        for (int i = 0; i < n; i++)
        {
            int num;
            cin >> num;
            if (num == 0)
            {
                count0++;
            }
            else
            {
                count1++;
            }
        }
        if (count0 >= k || count1 >= k || k - (k + 1) / 2 + 1 <= count1)
        {
            cout << 0 << endl;
        }
        else
        {
            cout << 1 << endl;
        }

    }
    return 0;
}